<?php
class news extends Activity {
    /** @var  ArticleModule */
    protected $article;
    function __construct() {
        $this->article=ArticleModule::init("article");
    }

    function indexTask($id=null){
        $article=$this->article;
        $articleData=$article->getDetail((int)$id);
        list($articleList,$articleTotal)=$article->getList("news",10,0);
        if(empty($articleData)){
            $articleData=reset($articleList);
        }
        $result=array("article"=>$articleData,"list"=>$articleList);
        View::displayAsHtml($result, "article-news.php");
        return null;
    }

    function systemTask($remark=null){
        $article=$this->article;
        $articleData=$article->getDetailByRemark($remark);
        if(empty($articleData)){
            return new Intent(404,"文章未找到");
        }
        $result=array("article"=>$articleData);
        View::displayAsHtml($result, "article.php");
        return null;
    }
    function complaintTask(){
        View::displayAsHtml(array(), "complaint.php");
    }
    function complaintSubmitTask($title,$content){
        if(empty($title)||empty($content)){
            $result['message']="请您完整填写标题和内容~";
        }else{
            $content=TextFilter::htmlCut($content,0);
            $r=$this->article->add($title,$content,'complaint');
            $result['message']=$r>0 ? "您的投诉已经提交，我们会认真考虑您的建议~":"提交失败，请重试~";
        }
        $result['url']=WebRouter::init()->getPage('news','complaint');
        View::displayAsHtml($result,"plugin/state/tips.php");
    }
}